import javax.bluetooth.UUID;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;


public class BtSunMIDlet extends MIDlet implements CommandListener {

//	public static WebMobileMIDlet02 instancia;

    Conexao conexao;

	private Display telaInicial;
	private Form form;
	private Command exit;
	private Command conectar;
	
	public BtSunMIDlet() {
		form = new Form("Web Mobile 02");
		exit = new Command("Sair", Command.CANCEL, 0);
		conectar = new Command("Contectar", Command.OK, 1);
		conexao = new BluetoothClient();
	}

	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		notifyDestroyed();
	}

	protected void pauseApp() {
	}

	protected void startApp() throws MIDletStateChangeException {
		telaInicial = Display.getDisplay(this);
		form.addCommand(exit);
		form.addCommand(conectar);
		form.setCommandListener(this);
		telaInicial.setCurrent(form);
	}

	public void commandAction(Command c, Displayable d) {
		if (c.equals(exit)) {
			try {
				destroyApp(true); // fecha a aplicacao
			} catch (MIDletStateChangeException e) {
				e.printStackTrace();
			}	
		} else if (c.equals(conectar)) {
			if (conexao.conectar()) {
				form.append("conectado!");
			} else {
				form.append("Problema na conexao!");
			}
//            util.iniciaInquiry( new UUID[]{ uuid } );
//            telaInicial.setCurrent( util.mostraBT() );
		}
	}
}
